package net.ezsteam;

import java.util.ArrayList;

import net.ezsteam.EzSteam_Register_Activity.MyAdapter;
import net.ezsteam.EzSteam_Register_Activity.ViewHolder;
import net.ezsteam.cons.EzSteam_Urls;
import net.ezsteam.object.EzSteam_ListItem;
import net.ezsteam.service.EzSteam_GetCars_WithRemove_Service;
import net.ezsteam.service.EzSteam_ProfileEdit_Save_Service;
import net.ezsteam.service.EzSteam_Register_Service;
import net.ezsteam.service.EzSteam_Service_ServiceType;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;


public class EzSteam_MyProfile_Edit_Activity extends Activity{

	private ListView myList;
	
	private String cusid = "";
	private String user = "";
	private String email = "";
	private String password = "";

    
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ezsteam_profile_edit);

        Bundle extras = getIntent().getExtras();

		if (extras != null) {
			cusid = extras.getString("cusid");
			user = extras.getString("name");
			email = extras.getString("email");
			password = extras.getString("password");
			
		}
        
        myList = (ListView) findViewById(R.id.list_vehicles);

        LayoutInflater inflater = getLayoutInflater();
        ViewGroup header = (ViewGroup)inflater.inflate(R.layout.ezsteam_profile_edit_header, myList, false);
        ViewGroup footer = (ViewGroup)inflater.inflate(R.layout.ezsteam_profile_edit_footer, myList, false);
        myList.addHeaderView(header, null, false);
        myList.addFooterView(footer, null, false);

        Button btn_submit = (Button)findViewById(R.id.btn_submit);
        final EditText txt_name = (EditText)findViewById(R.id.txt_name);
        final EditText txt_email = (EditText)findViewById(R.id.txt_email);
        final EditText txt_password = (EditText)findViewById(R.id.txt_password);
        final EditText txt_re_password = (EditText)findViewById(R.id.txt_re_password);

        txt_name.setText(user);
        txt_email.setText(email);
        txt_password.setText(password);
        txt_re_password.setText(password);
        
        btn_submit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(!txt_name.getText().toString().equals("") || !txt_email.getText().toString().equals("") || !txt_password.getText().toString().equals("") || !txt_re_password.getText().toString().equals("")){
					if(checkReEnterPass(txt_password.getText().toString(),txt_re_password.getText().toString())){
						EzSteam_ProfileEdit_Save_Service epss = new EzSteam_ProfileEdit_Save_Service(EzSteam_MyProfile_Edit_Activity.this,cusid,txt_name.getText().toString(),txt_email.getText().toString(),txt_password.getText().toString(),"");
						epss.execute(EzSteam_Urls.Update_Customer_Service);
					}else{
						Toast toast = Toast.makeText(EzSteam_MyProfile_Edit_Activity.this, "Passwords Different !!", Toast.LENGTH_SHORT);
						toast.show();
					}
				}else{
					Toast toast = Toast.makeText(EzSteam_MyProfile_Edit_Activity.this, "Fields Empty !!", Toast.LENGTH_SHORT);
					toast.show();
				}
				
			}
		});

        
	}

	
	private boolean checkReEnterPass(String pass,String repass){
		if(pass.equals(repass))return true;
		else return false;
	};
	
	@Override
	protected void onResume() {
		super.onResume();
		EzSteam_GetCars_WithRemove_Service gws = new EzSteam_GetCars_WithRemove_Service(EzSteam_MyProfile_Edit_Activity.this,myList,cusid);
        gws.execute(EzSteam_Urls.GetCar_Service+"/"+cusid.trim().toString());
	}
   
}
